<!--This file is the Logic part (Database part) for Registration.-->
<?php
include 'DBLibrary/config.php';
include 'DBLibrary/openDB.php';
mysql_select_db($dbname);

if (isset($_POST['submit'])) {
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $position = $_POST['position'];
    $email = $_POST['email'];
    $isAdmin = 0;
    switch ($position) {
        case "President": $isAdmin = 1;
            break;
        case "EVP Internals": $isAdmin = 1;
            break;
        case "EVP Externals": $isAdmin = 1;
            break;
        case "VP Documentations": $isAdmin = 1;
            break;
        case "VP Finance": $isAdmin = 1;
            break;
        case "VP Club Service": $isAdmin = 1;
            break;
        case "VP Community Service": $isAdmin = 1;
            break;
        case "VP Professional Service": $isAdmin = 1;
            break;
        case "VP International Service": $isAdmin = 1;
            break;
        default:$isAdmin = 0;
            break;
    }
    $queryExisting = mysql_query("select * from `rotaract`.`officer` where username='$username'");
    $resultExisting = mysql_fetch_array($queryExisting);

    if (empty($resultExisting)) {
        $confirm = mysql_query("INSERT INTO `rotaract`.`officer` (`firstName`, `lastName`, `username`, `password`, `position`, `isAdmin`, `email`) VALUES ('$firstname', '$lastname', '$username', '$password', '$position', $isAdmin, '$email');") or die(mysql_error());
    }
}
include 'DBLibrary/closeDB.php';
?>
